package cn.im.qywx.util.aes;
public class SampleUtils {


	private static SampleUtils g_instance = new SampleUtils();
	public static WXBizMsgCrypt wxcpt;

	public static SampleUtils getInstance() {
		return g_instance;
	}
	
//	public static void main(String[] args) {
//		String msgSignature="944c215bb7e86785a223090bc479006208c7f05e";
//		String timeStamp="1500542618";
//		String nonce="1769314400";
//		String postData="<xml><ToUserName><![CDATA[wx83b404b710b8ed05]]></ToUserName><Encrypt><![CDATA[b4XtwTkyOT/4XXHoHmlvkr3KCrXyEHvfZrphDYniv5rsstxK3bjX14PR5E7VxMOtgyJBT+phPWHFSgBUM26VrWsCKR8JBukVxNf/ZFE0vDQwpUUi/NtrcEDxOOlgxys2C59z7ZsR91Uj94pUI9jbDyOODwoSNVNds3YT9y5Ivd6nqFHIppQn3iC4M52eULp7jWAQ90ow0LF3V3XSyvg6nDgBMWU+bgT2QntTSUbtaIvUG5KODZBPYRIbNWJcvivpObYe+ZbgTHgkCmZfr3PcBff9ffbWEkyY+LeOkbt+EdsgfTv/gEnR3ExIx80J6K5N+rm1Ob6b1Xh15fKp5OI0YFXhrxuy4BPvYjrxRVceMqLMIGG0puqd/CgVZ7Nz2JQ7FawFccwqzP+vF8whoECksA9VUcmQWUO5oKqtIwtmYMsKI6BfvGeTuUACfFDBjWKjEUAJUCPBEB2IFq0GzLof+Q==]]></Encrypt><AgentID><![CDATA[37]]></AgentID></xml>";
//		String result = SampleUtils.getInstance().DecryptMsg(msgSignature, timeStamp, nonce, postData);
//		System.out.println(result);
//	}
	
	public SampleUtils(){
		try {
			wxcpt = new WXBizMsgCrypt("BEwMypovubuvBvIMBIWywXQWb9Zn", "WeeoHuUubLafrB7OlifcqxF67i9bxCJKJw1NdxD1aTE", "wx83b404b710b8ed05");
		} catch (AesException e) {
			System.out.println(" wx WXBizMsgCrypt method return exception.");
			e.printStackTrace();
		}
	}
	
	public String DecryptMsg(String msgSignature,String timeStamp,String nonce,String postData){
		String result = null;
		try {
			result = wxcpt.DecryptMsg(msgSignature, timeStamp, nonce, postData);
		} catch (AesException e) {
			System.out.println(" WXBizMsgCrypt DecryptMsg method return exception.");
			e.printStackTrace();
		}
		return result;
	}
	
	public String EncryptMsg(String sRespData, String sReqTimeStamp,String sReqNonce){
		String sEncryptMsg = null;
		try {
			sEncryptMsg = wxcpt.EncryptMsg(sRespData, sReqTimeStamp, sReqNonce);
		} catch (AesException e) {
			System.out.println(" WXBizMsgCrypt EncryptMsg method return exception.");
			e.printStackTrace();
		}
		return sEncryptMsg;
	}
	
}
